package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {


    //根据收货人的地址id查询收货地址信息
    //回显地址
    @Select("select * from address_book where id=#{id}")
    AddressBook findById(Long id);

    //查询当前登录用户的所有地址信息
    List<AddressBook> findList(AddressBook addressBook);

    //新增地址
    @Insert("INSERT INTO address_book VALUES (null,#{userId}, #{consignee}, #{sex}, #{phone}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}, #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})")
    void save(AddressBook addressBook);

    //将登录人的所有地址都设置为0,非默认
    @Update("update address_book set is_default = 0 where user_id = #{userId}")
    void updateByUserId(Long userId);

    //把当前地址id更新为默认1
    void update(AddressBook addressBook);

    //删除地址
    @Delete("delete from address_book where id=#{id}")
    void deleteById(Long id);

    //修改地址
    void updateAddress(AddressBook addressBook);
}
